<style scoped lang="less">
	.item {
		background: white;
		padding: 2vw 0;
	}
	
	.item-goods-img {
		width: 15vw;
		height: 15vw;
		padding: 1vw;
	}
	
	.item-goods-info {
		display: flex;
	}
	
	.item-goods-info-content {
		width: 80vw;
		text-align: left;
		padding: 1vw;
	}
	
	.item-goods-info-title {
		font-size: 0.4rem;
		line-height: 1.2;
		min-height: 0.8rem;
	}
	
	.item-goods-info-sku {
		display: flex;
		justify-content: space-between;
		font-size: 0.4rem;
		color: @--gray;
	}
	
	.btn-container {
		margin-top: 20vh;
	}
</style>
<template>
	<div v-if="order_data!=null">
		<div class="item">
			<div class="item-goods-info">
				<img class="item-goods-img" :src="GLOBAL.getUrl(order_data.item_data.goods_img,true,false)">
				<div class="item-goods-info-content">
					<div class="item-goods-info-title">
						{{order_data.item_data.goods_title}}
					</div>
					<div class="item-goods-info-sku">
						<span class="sku-title">{{order_data.item_data.sku_title}}</span>
						<span class="goods-num">×{{order_data.item_data.goods_num}}</span>
					</div>
				</div>
			</div>
		</div>
		<div class="btn-container">
			<van-button class="btn-ok" @click="showNotice" type="primary" :loading="loading"  loading-text="核销中...">确认核销</van-button>
		</div>
	</div>
</template>
<script>
  import Vue from 'vue';
  import {Dialog, Button} from 'vant';
  import {getOrderByCode,checkCode} from '@/api/admin/order';

  Vue.use(Button);
  export default {
    name: 'check-code',
    data() {
      return {
        code: null,
        loading: false,
        order_data: null
      };
    },
    created() {
      this.code = this.$route.query.code;
      this.getData();
    },
    methods: {
      getData() {
        let vm = this;
        getOrderByCode(this.code).then(rep => {
          vm.order_data = rep.data.data;
        })
      },
      showNotice() {
        let vm = this;
        Dialog.confirm({
          title: '确认核销吗？',
          message: "您即将为商品<br/>【" + vm.order_data.item_data.goods_title + "】<br/>进行核销，请确认"
        }).then(() => {
          vm.submit();
        }).catch(() => {
          // on cancel
        });
      },
      submit() {
        let vm = this;
        vm.loading = true;
        checkCode(this.code).then(rep => {
          vm.loading = false;
          Dialog.alert({
            title: '核销成功',
            message: "商品<br/>【" + vm.order_data.item_data.goods_title + "】<br/>核销成功!"
          }).then(() => {
          
          })
        },error => {
          vm.loading = false;
        })
      }

    }
  }
</script>